/*******************************************************************************
 * The MOSES project, model based software engineering of networked embedded systems.
 * 
 * Copyright (C) 2010-2013, University of Applied Sciences Wildau,
 * Telematics Research Group, http://www.tm.th-wildau.de/research-group
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses>.
 * 
 * Contributors:
 *     University of Applied Sciences Wildau - initial API and implementation
 * 
 * If you are interested in a commercial license please contact us via 
 * e-mail: ralf.vandenhouten@th-wildau.de.
 ******************************************************************************/
package de.thwildau.tm.moses.asn1.util;

import org.eclipse.xtext.naming.QualifiedName;

/**
 * Default implementation of {@link EObjectResourceDescription}.
 * 
 * @author Thomas Kistel
 * @version $Revision: 763 $
 */
/* package */class EObjectResourceDescriptionImpl<T> implements EObjectResourceDescription<T> {

    private final T eObject;
    private final QualifiedName fullQualifiedName;


    public EObjectResourceDescriptionImpl(T eObject, QualifiedName fullQualifiedName) {
        this.eObject = eObject;
        this.fullQualifiedName = fullQualifiedName;
    }

    /*
     * (non-Javadoc)
     * @see de.thwildau.tm.moses.asn1.util.EObjectResourceDescription#getObject()
     */
    @Override
    public T getObject() {
        return eObject;
    }

    /*
     * (non-Javadoc)
     * @see de.thwildau.tm.moses.asn1.util.EObjectResourceDescription#getPackageName()
     */
    @Override
    public QualifiedName getPackageName() {
        if(fullQualifiedName.getSegmentCount() > 1)
            return fullQualifiedName.skipLast(1);
        return null;
    }
    
    /*
     * (non-Javadoc)
     * @see de.thwildau.tm.moses.asn1.util.EObjectResourceDescription#getClassName()
     */
    public String getClassName() {
       return fullQualifiedName.getLastSegment(); 
    }

    /*
     * (non-Javadoc)
     * @see de.thwildau.tm.moses.asn1.util.EObjectResourceDescription#getFullQualifiedName()
     */
    @Override
    public QualifiedName getFullQualifiedName() {
        return fullQualifiedName;
    }

    /*
     * (non-Javadoc)
     * @see EObjectResourceDescription#getFilePath(EObjectResourceDescription.Language)
     */
    @Override
    public String getFilePath() {
        return fullQualifiedName.toString().replace(".", "/") + ".java";
        
//        switch (lang) {
//            case Java:
//                return fullQualifiedName.toString().replace(".", "/") + ".java";
//            default:
//                throw new IllegalArgumentException();
//        }
    }
    
    @Override
    public String toString() {
        return "EObjectDesc[fqn=" + getFullQualifiedName() + ", filePath=" + getFilePath() + "]";
    }
}
